Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pre-defined arguments to support override symlink prefix and append targets #113

Closed
wants to merge 1 commit into from

Conversation

LoSealL
Copy link
Contributor

@LoSealL LoSealL commented Mar 18, 2023

Problem statement

Currently bazel-compile-commands-extractor works very well in most cases, but there are still some rare cases where users may specify a different output directory other than the default "bazel-*".
On the other hand, if users add some new source files and want clangd to index them, they probably do not want to re-run the whole extractor, especially when users add new files frequently (usually at the beginning of a project or adding new features to an existing project), just because a total re-run takes quite a few miniutes.

Solution

Hence we propose a PR to solve above two problems:
We add explicit argument parser to parse two pre-defined arguments: "-b", "--bazel-out" and "-t", "--targets":

  • Override symlink: bazel run @hedron_compile_commands//:refresh_all -- --bazel-out=mypredix-
  • Append targets: Only parser //foo:bar target and append to existing compile commands. bazel run @hedron_compile_commands//:refresh_all -- -t "//foo:bar"

- Override symlink:
  bazel run @hedron_compile_commands//:refresh_all -- --bazel-out=mypredix-
- Append targets:
  Only parser //foo:foo target and append to existing compile commands.
  bazel run @hedron_compile_commands//:refresh_all -- -t "//foo"
@cpsauer
Copy link
Contributor

cpsauer commented May 4, 2023

Hello again, @LoSealL! Great to hear from you.

I hear you on both needs.

On the faster, incremental update:

I totally get that for very large codebases, rerunning the whole thing is too slow. (There are the usual speed tricks in the README, but it sounds like those are insufficient.)

There's a trap if you do it per-sub-target, though, and that's that the top-level-target often configures the targets it depends on, meaning that the commands for the sub targets are wrong if you ask for them the obvious way 🤦🏻. Cross-compiling, e.g. to mobile or embedded, is a key example of this. You'll get commands for the host platform, not the target platform. Plus, getting all dependencies of a sub-target can still be overwhelming.

So instead, I've been working with @xinzhengzhang for a while on a --file flag that lets an editor quickly ask for the correctly configured flag for a single file. The idea is that the editor would be configured to auto-call this tool to get the right command when files are opened or created, keeping things up to date, just in time.

Does that sound like it'd solve things for you too?

If so, we could really use your help, double checking that it works for you and resolving some of the remaining TODOs in the code. (Am I right in remembering that you'd helped with windows before? If so, there are some bite-sized windows TODOs we could really use your help on.)

The work is going on in #99 with the early design discussion in #93. If you're down to help, I'm hoping he can just give you commit access the branch we're using for the feature.

For Bazel-out:
I hear you--it'd be nice to handle all combos of bazel flags. But this one is significantly trickier than you might think, since you also have to port over all the bazel flags that reference bazel-out. There have been some other efforts at this and at adding an option to remove the external symlink (run a quick search through PRs and issues), but I really think it's more hassle than it's worth it, since it makes things much simpler to have a workspace that mirrors the compilation sandbox. That said, I remain open to it if you want to do the work.

Cheers--and thanks for being the kind of person that looks for ways to help improve things!
Chris

@LoSealL
Copy link
Contributor Author

LoSealL commented May 5, 2023

Thanks @cpsauer, indeed it will be more convenient to interact with editor automatically, I will study how #99 is designed.

BR

@LoSealL LoSealL closed this May 5, 2023
@cpsauer
Copy link
Contributor

cpsauer commented May 5, 2023

Thanks for taking a look, and being down to merge efforts @LoSealL. Please let me know what you think.

And for my learning, what does BR stand for?

@LoSealL
Copy link
Contributor Author

LoSealL commented May 6, 2023

Best regards :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants